package net.ocps.tchs.soap.event.events;

import net.ocps.tchs.soap.entity.Entity;
import net.ocps.tchs.soap.event.EventA;

public class FollowEvent extends EventA {

	public FollowEvent( Entity target ) {
		this.target = target;
	}

	@Override
	public void process(Entity e) {
		try {
			if( target != null && ( e.getX()+440 >= target.getX() && e.getX()-440 <= target.getX()) ) {
				if( e.getX() > target.getX() ) {
					e.setX( -40.5f );
					e.direction = -1;
				} else if( e.getX() < target.getX() ) {
					e.setX( 40.5f );
					e.direction = 1;
				}
			}
		} catch( Exception ee ) {
			//non existent target
		}
	}

	Entity target;
}
